<?php

use swap\rdb_model;
use swap\value;

class user_info_model extends rdb_model {
	
	public static $gender = array(
		1 => '男',
		2 => '女',
	);
	
	public static $political_status = array(
		1 => '中共党员(含预备党员)',
		2 => '共青团员',
		3 => '群众',
		0 => '保密',
	);
	
	public static $contact_type = array(
		1 => '移动电话',
		2 => '固定电话',
	);
	
	public static $marital = array(
		1 => '未婚',
		2 => '已婚',
		0 => '保密',
	);
	
	public static $id_type = array(
		1 => '身份证',
		2 => '护照',
		3 => '军官证',
		4 => '其他',
	);
	
	const username_length = 25;
	const address_length = 140;
	const postal_code_length = 6;
	const email_length = 60;
	const homepage_length = 140;
	
	public static function prop_rules($operation) {
		$rules = array(
			'edit' => self::user_info_id_rule() + self::username_rule() + self::gender_rule() + self::birthday_rule() + self::experience_rule() + self::marital_rule() + self::id_rule() + self::political_status_rule() + self::resident_rule() + self::address_rule() + self::postal_code_rule() + self::contact_rule() + self::homepage_rule(),
		);
		return $rules[$operation];
	}
	
	protected static function user_info_id_rule() {
		$rule = array(
			'user_info_id' => array(
				'change_to' => 'int',
			),
		);
		return $rule;
	}
	protected static function username_rule() {
		$rule = array(
			'username' => array(
				'change_to' => 'string',
				'cannot_be' => array('', '亲,姓名不能为空哦'),
				'char_size' => array(1, self::username_length, '亲,姓名应少于%d个字符哦'),
			),
		);
		return $rule;
	}
	protected static function gender_rule() {
		$rule = array(
			'gender' => array(
				'change_to' => 'int',
			),
		);
		return $rule;
	}
	protected static function birthday_rule() {
		$rule = array(
			'birthday' => array(
				'change_to' => 'string',
				'cannot_be' => array('', '亲,出生日期不能为空哦'),
			),
		);
		return $rule;
	}
	protected static function experience_rule() {
		$rule = array(
			'experience' => array(
				'change_to' => 'string',
				'cannot_be' => array('', '亲,参加工作时间不能为空哦'),
			),
		);
		return $rule;
	}
	protected static function marital_rule() {
		$rule = array(
			'marital' => array(
				'change_to' => 'int',
			),
		);
		return $rule;
	}
	protected static function id_rule() {
		$rule = array(
			'id_type' => array(
				'change_to' => 'int',
			),
			'id_number' => array(
				'change_to' => 'string',
				'cannot_be' => array('', '证件号不能为空'),
			),
		);
		return $rule;
	}
	protected static function political_status_rule() {
		$rule = array(
			'political_status' => array(
				'change_to' => 'int',
			),
		);
		return $rule;
	}
	protected static function resident_rule() {
		$rule = array(
			'resident_province' => array(
				'change_to' => 'int',
			),
			'resident_city' => array(
				'change_to' => 'int',
			),
			'live_province' => array(
				'change_to' => 'int',
			),
			'live_city' => array(
				'change_to' => 'int',
			),
		);
		return $rule;
	}
	protected static function address_rule() {
		$rule = array(
			'address' => array(
				'change_to' => 'string',
				'pass_if_be' => '',
				'char_size' => array(3, self::address_length, '通信地址应%d到%d个字符'),
			),
		);
		return $rule;
	}
	protected static function postal_code_rule() {
		$rule = array(
			'postal_code' => array(
				'change_to' => 'int',
				'pass_if_be' => 0,
				'char_size' => array(self::postal_code_length, self::postal_code_length, '非法的邮政编码'),
			),
		);
		return $rule;
	}
	protected static function contact_rule() {
		$rule = array(
			'contact_type' => array(
				'change_to' => 'int',
			),
			'contact_num' => array(
				'change_to' => 'string',
				'cannot_be' => array('', '联系方式不能为空'),
			),
		);
		return $rule;
	}
	protected static function homepage_rule() {
		$rule = array(
			'homepage' => array(
				'change_to' => 'string',
				'char_size' => array(0, self::homepage_length, '个人主页/博客应少于%d个字符'),
			),
		);
		return $rule;
	}
	
	public static function email_rule() {
		$rule = array(
			'email' => array(
				'change_to' => 'string',
				'cannot_be' => array('', 'E-mail不能为空'),
				'char_size' => array(1, self::email_length, 'E-mail长度应少于%d字符'),
				'value_type' => array(value::email_type, '非法的E-mail地址'),
			),
		);
		dump($rule);
		return $rule;
	}
}